package com.zk.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.zk.config.AliPayConfig;
import com.zk.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
//调用支付宝接口
@RestController
public class PaymentController {
    @Autowired
    AlipayService alipayService;
    @RequestMapping("/pay")
    public void payMent(HttpServletResponse response, HttpServletRequest request, HttpSession session) {
        try {
            alipayService.aliPay(response, request,session);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @RequestMapping("/notifyPay")
    public void notifyPay(HttpServletRequest request) throws AlipayApiException{
        Map<String,String> paramsMap =new HashMap<String,String>();
        boolean  signVerified = AlipaySignature.rsaCheckV1(paramsMap, AliPayConfig.alipay_public_key, "utf-8", "RSA2");
        if(signVerified){
            System.out.println(paramsMap);
        }
    }

}
